<template>
  <!-- 列表切换框组件 -->
  <view class="nav">
    <view class="nav__list">
      <view
        v-for="item in means"
        :key="item.id"
        class="nav__item"
        @tap="handleChange(item)"
        :class="{'nav__item_active': select === item.id}"
      >{{item.name}}</view>
    </view>
    <view class="nav_btn" v-if="chaper_sections===50" @click="handleClick">添加笔记</view>
    <view>
      <slot></slot>
    </view>
  </view>
</template>

<script>
/**
 * lessonCatalog 菜单组件 （未完成,需要业务支持）
 * @property {Array} means 菜单的数据列
 * @property {Number} select 当前的选择项下标
 */
export default {
  name: "lesson-catalog",
  model: {
    prop: "chaper_sections",
    event: "change"
  },
  data() {
    return {
      // select: 10
    };
  },
  props: {
    chaper_sections: {
      type: Number,
      default: 10
    },
    select: {
      type: Number,
      default: 10
    },
    means: {
      type: Array,
      default() {
        return [
          { name: "视频", id: 10 },
          { name: "讲义", id: 20 }
          //   { name: "练习", id: 30 }
        ];
      }
    }
  },
  methods: {
    handleChange(item) {
      this.$emit("change", item.id);
      // this.select = item.id
    },
    handleClick() {
      this.$emit("addNote");
    }
  }
};
</script>

<style lang="scss" scope>
.nav {
  position: relative;
  .nav__list {
    display: flex;
    align-items: center;
    height: 60rpx;
    margin-bottom: 40rpx;
    .nav__item {
      color: #666;
      font-size: 32rpx;
      margin-right: 61rpx;
      position: relative;
      &.nav__item_active {
        color: #333;
        font-size: 36rpx;
        font-weight: bold;
        &::after {
          width: 50%;
        }
      }
      &::after {
        content: "";
        width: 0;
        height: 8rpx;
        background-color: $uni-color-primary;
        position: absolute;
        border-radius: 4px;
        left: 50%;
        bottom: -12rpx;
        transform: translateX(-50%);
        transition: 0.3s;
      }
    }
  }
  .nav_btn {
    position: absolute;
    right: 0;
    top: 10rpx;
    border-radius: 10rpx;
    background-color: rgb(22, 155, 213);
    color: #fff;
    padding: 10rpx;
  }
}
</style>
